﻿using KendoUIGridSignalR.Hubs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Timers;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace KendoUIGridSignalR
{
    public class MvcApplication : System.Web.HttpApplication
    {
        // Author: Otto Neff | webapps-in-action.com
        private static System.Timers.Timer UpdateTimer;
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteTable.Routes.MapHubs();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            UpdateTimer = new System.Timers.Timer(10000);
            UpdateTimer.Elapsed += new ElapsedEventHandler(UpdateTimer_Elapsed);
            UpdateTimer.Interval = 5000;
            UpdateTimer.Enabled = true;
        }

        void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Random rnd = new Random();
            UpdateTimer.Interval = rnd.Next(400, 2500);
            StockHub.Trigger();
        }
    }
}